package com.mybatis.lo.builder;

import com.mybatis.lo.config.Configuration;
import org.dom4j.Element;

import java.util.List;

/**
 * 解析Mapper映射文件的构建器
 * @author zhangbh
 * 2023-06-16 07:32
 **/
public class XMLMapperBuilder extends BaseBuilder {
    public XMLMapperBuilder(Configuration configuration) {
        super(configuration);
    }

    public void loadMapper(Element element) {
        String namespace = element.attributeValue("namespace");
        if (isNullOrEmpty(namespace)) {
            System.out.println("没有命名空间");
            return;
        }
        // todo 只处理 select 标签
        List<Element> selectElements = element.elements("select");
        XMLStatementBuilder statementBuilder = new XMLStatementBuilder(configuration);
        for (Element selectElement : selectElements) {
            statementBuilder.loadStatementNode(namespace, selectElement);
        }
    }
}
